/*
 * HalcyonV1.h
 *
 * Created: 01.05.2012 12:28:46
 *  Author: maxim.karban@gmail.com
 */ 

#ifndef _i2c_master_h_
#define _i2c_master_h_ 1

#include "HalcyonV1.h"

#include <avr/io.h>


/* I2C clock in Hz */
#define SCL_CLOCK  100000UL

/* TWCR */
/*#define TWINT   7
#define TWEA    6
#define TWSTA   5
#define TWSTO   4
#define TWWC    3
#define TWEN    2
#define TWIE    0*/

/** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */
#define I2C_READ    1

/** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */
#define I2C_WRITE   0

#define I2C_START 0x08
#define I2C_REPEATED_START 0x10
#define I2C_SLA_W_ACK 0x18
#define I2C_SLA_W_NOACK 0x20
#define I2C_SLA_R_ACK 0x40
#define I2C_SLA_R_NOACK 0x48
#define I2C_DATA_ACK 0x28
#define I2C_DATA_NOACK 0x30
#define I2C_ARBITRATION_LOST 0x38


//volatile int I2C_Error = 0;
extern void i2c_init(void);
extern void i2c_set_dev(unsigned char DevAddr);
extern void i2c_set_mem(unsigned char MemAddr);
extern void i2c_send_data(unsigned char Data);
extern void i2c_write(unsigned char DevAddr, unsigned char MemAddr, unsigned char Data);
extern void i2c_read(unsigned char *Buffer, unsigned char DevAddr, unsigned char MemAddr, unsigned char Cnt, unsigned char JustRead, unsigned char SetEnd);

#endif
